import { ref } from 'vue'
import { defineStore } from 'pinia'
import type { User } from '@/types/user'

export const useUserStore = defineStore(
  'cp-counter',
  () => {
    // 1. 提供用户信息
    const user = ref<User>()

    // 2.修改用信息的方法
    const setUser = (val: User) => {
      user.value = val
    }

    // 3.清空用户，退出后使用
    const delUser = () => {
      user.value = undefined
    }
    return { user, setUser, delUser }
  },
  {
    // 开启持久化存储
    persist: true
  }
)
